package de.velvettear.squirrel.kernel;

import java.util.HashMap;
import java.util.Vector;

import android.database.Cursor;
import de.velvettear.squirrel.database.Column;
import de.velvettear.squirrel.database.Column.ColumnDataType;

public class NFCTag extends Base {

public final static String TABLENAME = "NFCTag";
	
	public String m_sTagID = "";
	public String m_sType = "";
	public String m_sAction = "";
	public String m_sExtras = "";
		
	public NFCTag() {
		
	}
	
	public String getTableName() {
		return TABLENAME;
	}
	
	public boolean hasExtra(String extra) {
		if (m_sExtras.contains(extra)) {
			return true;
		} else {
			return false;
		}
	}
	
	public boolean hasExtras() {
		if (m_sExtras.trim().length() > 0 && !m_sExtras.trim().equals("")) {
			return true;
		} else {
			return false;
		}
	}
	
	public void setExtras(String extras) {
		m_sExtras = extras;
	}
	
	public void addExtra(String extra) {
		if (!m_sExtras.contains(extra)) {
			if (m_sExtras.trim().length() == 0) {
				m_sExtras = extra;
			} else {
				m_sExtras += "|" + extra;
			}				
		}
	}
	
	public Vector<String> getExtras() {
		Vector<String> extras = new Vector<String>();		
		
		String[] splitString = m_sExtras.split("\\|");
		for (String part : splitString) {
			extras.add(part);
		}		
		
		return extras;
	}
	
	public Vector<NFCTag> getTagByTagID(String m_sTagID) {
		return select("m_sTagID = '" + m_sTagID + "'", null, false);
	}
	
	public HashMap<String,Object> getData() {
		HashMap<String, Object> retVal = super.getData();
		retVal.put("m_sTagID", 			this.m_sTagID);
		retVal.put("m_sType", 			this.m_sType);
		retVal.put("m_sAction", 		this.m_sAction);
		retVal.put("m_sExtras",			this.m_sExtras);
		return retVal;  
	}
	
	public void setData(Cursor c) {		   
		super.setData(c);
		this.m_sTagID 		= c.getString(c.getColumnIndex("m_sTagID"));
		this.m_sType 		= c.getString(c.getColumnIndex("m_sType"));
		this.m_sAction 		= c.getString(c.getColumnIndex("m_sAction"));
		this.m_sExtras 		= c.getString(c.getColumnIndex("m_sExtras"));
	}
	
	public static Vector<Column> getColumnConfig() {                          
		Vector<Column> retVal = Base.getColumnConfig();                    
                                                                                
		retVal.add(new Column("m_sTagID", 4000,	false, ColumnDataType.sql_varchar));	
		retVal.add(new Column("m_sType", 4000, false, ColumnDataType.sql_varchar));	
		retVal.add(new Column("m_sAction", 4000, false, ColumnDataType.sql_varchar));	
		retVal.add(new Column("m_sExtras", 4000, false, ColumnDataType.sql_varchar));
		
		return retVal;																   
	}	
	
}
